<?php
/**********************
**File Name: index.php
**Date Created: 4/13/2009
**Copyright 2009 Tomorrow Tech Industries
**Contact: RPITomorrowTech@gmail.com
**********************/

/*******
This is a software intellistrip demo page
It is intended to be used for testing to see if remote agents are updating this server
*******/

require_once('private/shared/errors.inc');
require_once('private/shared/intellistrip.inc');
require_once('private/intellistrip_server.inc');
require_once('private/software_intellistrip_server.inc');
require_once('private/db_access.inc');
require_once('private/software_intellistrip_db.inc');

//Intellistrip power state is currently not used
//This will become more properly defined when put into more use 
function determineState(&$state)
{
	if($state == 0) 
	{
		$state = "On";
	}
	else if($state == 1)
	{
		$state = "Off";
	}
	else
	{
		$state = "Error";
	}
}

//Output HTML showing a port's power level
function displayPowerLevel($portID, $portPower)
{
	if($portPower == 0)
	{	
		echo "<img src=\"img/off_light.png\">";
	}
	else if($portPower <= 100)
	{
		echo "<img src=\"img/on_light.png\">";
	}
}

//Display's this web page
function displayPage()
{
	echo "
	<HTML>
	";
	
	//Header information
	//Screen refreshes as a simple way to view in real time the updates to this server
	echo "
		<HEAD>
		<meta HTTP-EQUIV=\"Refresh\" CONTENT=\"1\">\n
		<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n
		<meta HTTP-EQUIV=\"Expires\" CONTENT=\"-1\">\n
		</HEAD>\n
		";
	
	
	// Display the results
	echo "<BODY><BR><b><font size = 4>Intellistrip: </font></b><BR>";
	
	$intellistripServer = new SoftwareIntellistripServer("");
	if( TT_FAILED($intellistripServer->getIntellistripInformation($vendorName, $modelNumber,
													$modelVersion, $serialNumber,
													$numberPorts, $state)) )
	{
		echo "Failed to get Intellistrip Information. <BR>";
	}
	else
	{
		//Print state
		determineState($state);
		echo "
			<table CELLPADDING = 7>
			<tr><td> <b>Vendor Name: </b></td>
			<td>  " . $vendorName . "</td></tr>
			<tr><td> <b>Model Number: </b></td>
			<td>  " . $modelNumber . "</td></tr>
			<tr><td> <b>Version: </b></td>
			<td>  " . $modelVersion . "</td></tr>
			<tr><td> <b>Serial: </b></td>
			<td>   " . $serialNumber . "</td></tr>
			<tr><td> <b>State: </b></td>
			<td>  " . $state . "</td></tr><br>
			<tr><td> <b>Number of Ports: </b></td>
			<td>  " . $numberPorts . "</td></tr> 
			</table>
			";
		
		//Loop to display each port
		for($i = 1; $i <= $numberPorts; $i++)
		{
			if( TT_FAILED($intellistripServer->getPortPower($i, $portPower)) )
			{ 
				echo " Failed to get Port power: " . $i ."<BR> ";
				
			}
			else
			{
			
				echo "
					<table CELLPADDING = 3>
					<tr><td> &nbsp; &nbsp; &nbsp;
					<b>   Port " . $i . ":</b> &nbsp; "; 
				
				displayPowerLevel($i, $portPower);
				
				echo " 
					&nbsp; &nbsp; &nbsp; <Font size = 2> POWER LEVEL:  </font> </td>
					<td> <Font size = 2> &nbsp;" . $portPower . "% &nbsp; </font> </td></tr> 
					";
			}
			
		}
		
		echo "</table>";
	}
	
	echo "
		</BODY>\n
		</HTML>\n
		";
}

displayPage();
?>
